<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>接口管理</title>
    <link rel="stylesheet" type="text/css" href="../css/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../css/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../css/themes/color.css">
    <link rel="stylesheet" type="text/css" href="../css/style.css">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../js/config.js"></script>
</head>
<body>
<table id="dg" title="" class="easyui-datagrid" fit="true" multiSort="true"
       toolbar="#query" footer="#toolbar" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="platformName" sortable="true" width="50">平台名称</th>
        <th field="shopCode" sortable="true" width="50">店铺编码</th>
        <th field="shopName" sortable="true" width="50">店铺名称</th>
        <th field="baseUrl" sortable="true" width="200">Api基础Url</th>
        <th field="appKey" sortable="true" width="50">AppKey</th>
        <th field="appSecret" sortable="true" width="50">AppSecret</th>
        <th field="description" sortable="true" width="50">描述</th>
        <th field="createUser" sortable="true" width="50">创建人</th>
        <th field="createTime" sortable="true" width="50" formatter="CommonUtil.dateFormatter">创建时间</th>
        <th field="updateUser" sortable="true" width="50">修改人</th>
        <th field="updateTime" sortable="true" width="50" formatter="CommonUtil.dateFormatter">修改时间</th>
    </tr>
    </thead>
</table>
<div id="query" style="padding:2px 5px;">
    外卖平台:
    <select id="qPlatformId" class="easyui-combobox" panelHeight="auto" style="width:100px">
    </select>
    店铺名称:
    <select id="qShopId" class="easyui-combobox" panelHeight="auto" style="width:200px">
    </select>
    <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="PlatformShop.loadData()">查询</a>
</div>
<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true"
       onclick="PlatformShop.newPlatformShop()">新增</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true"
       onclick="PlatformShop.editPlatformShop()">修改</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true"
       onclick="PlatformShop.deletePlatformShop()">删除</a>
</div>

<div id="dlg" class="easyui-dialog" style="width:500px;height:400px;padding:10px 20px"
     closed="true" buttons="#dlg-buttons">
    <div class="ftitle">接口信息</div>
    <form id="fm" class="form" method="post" novalidate>
        <div class="fitem">
            <label>外卖平台:</label>
            <select id="platformId" name="platformId" class="easyui-combobox" panelHeight="auto" required="true">
            </select>
        </div>
        <div class="fitem">
            <label>接口店铺:</label>
            <select id="shopId" name="shopId" class="easyui-combobox" panelHeight="auto" required="true">
            </select>
        </div>
        <div class="fitem">
            <label>店铺标识:</label>
            <input id="shopPid" name="shopPid" class="easyui-textbox" required="true"/>
        </div>
        <div class="fitem">
            <label>baseUrl:</label>
            <input id="baseUrl" name="baseUrl" class="easyui-textbox" required="true"/>
        </div>
        <div class="fitem">
            <label>appKey:</label>
            <input id="appKey" name="appKey" class="easyui-textbox" required="true"/>
        </div>
        <div class="fitem">
            <label>appSecret:</label>
            <input id="appSecret" name="appSecret" class="easyui-textbox" required="true"/>
        </div>
        <div class="fitem">
            <label>描述:</label>
            <input id="description" name="description" class="easyui-textbox" data-options="multiline:true"
                   style="height:50px"/>
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok"
       onclick="PlatformShop.savePlatformShop()"
       style="width:90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel"
       onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div>
<script type="text/javascript">
    $(function () {
        PlatformShop.loadPlatform();
        PlatformShop.loadShop();
    });

    window.PlatformShop = {
        id: 0,
        loadComboBox: function (id, data) {
            $('#' + id).combobox({
                valueField: 'id',
                textField: 'text',
                data: data
            });
        },
        loadPlatform: function () {
            $('#qPlatformId').combobox({
                method: 'GET',
                url: window.BASEPATH + 'platform/dropdown',
                valueField: 'id',
                textField: 'text',
                loadFilter: function (data) {
                    if (data.suc == true) {
                        var rtn = data.result.rows;
                        PlatformShop.loadComboBox("platformId", rtn);
                        return rtn;
                    } else {
                        return null;
                    }
                }
            });
        },
        loadShop: function () {
            $('#qShopId').combobox({
                method: 'GET',
                url: window.BASEPATH + 'shop/dropdown',
                valueField: 'id',
                textField: 'text',
                loadFilter: function (data) {
                    if (data.suc == true) {
                        var rtn = data.result.rows;
                        PlatformShop.loadComboBox("shopId", rtn);
                        return rtn;
                    } else {
                        return null;
                    }
                }
            });
        },
        loadData: function () {
            $('#dg').datagrid({
                method: 'GET',
                url: window.BASEPATH + 'platformShop',
                queryParams: {
                    platformId: $('#qPlatformId').combobox('getValue'),
                    shopId: $('#qShopId').combobox('getValue')
                },
                loadFilter: function (data) {
                    if (data.suc == true) {
                        return data.result;
                    } else {
                        $.messager.show({
                            title: 'Error',
                            msg: data.message
                        });
                        return null;
                    }
                }
            });
        },
        newPlatformShop: function () {
            $('#dlg').dialog('open').dialog('center').dialog('setTitle', '新增');
            $('#fm').form('clear');
            PlatformShop.id = 0;
        },
        editPlatformShop: function () {
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $('#dlg').dialog('open').dialog('center').dialog('setTitle', '修改');
                $('#fm').form('load', row);
                PlatformShop.id = row.id;
            }
        },
        savePlatformShop: function () {
            var model = {
                platformId: $('#platformId').combobox('getValue'),
                shopId: $('#shopId').combobox('getValue'),
                shopPid: $("#shopPid").val(),
                baseUrl: $("#baseUrl").val(),
                appKey: $("#appKey").val(),
                appSecret: $("#appSecret").val(),
                description: $("#description").val()
            }
            if (PlatformShop.id == 0) {
                //新增
                $.ajax({
                    type: "POST",
                    url: window.BASEPATH + 'platformShop',
                    contentType: "application/json;charset=UTF-8",
                    dataType: "json",
                    data: JSON.stringify(model),
                    success: function (data, textStatus, jqXHR) {
                        if (data.suc) {
                            $('#dlg').dialog('close');
                            $('#dg').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: data.message
                            });
                        }
                    }
                });
            } else {
                //修改
                var row = $('#dg').datagrid('getSelected');
                $.ajax({
                    type: "PUT",
                    url: window.BASEPATH + 'platformShop/' + row.id,
                    contentType: "application/json;charset=UTF-8",
                    dataType: "json",
                    data: JSON.stringify(model),
                    success: function (data, textStatus, jqXHR) {
                        if (data.suc) {
                            $('#dlg').dialog('close');
                            $('#dg').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Error',
                                msg: data.message
                            });
                        }
                    }
                });
            }
        },
        deletePlatformShop: function () {
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $.messager.confirm('Confirm', '确定删除?', function (r) {
                    if (r) {
                        $.ajax({
                            type: "DELETE",
                            url: window.BASEPATH + 'platformShop/' + row.id,
                            dataType: "json",
                            success: function (data, textStatus, jqXHR) {
                                if (data.suc) {
                                    $('#dg').datagrid('reload');
                                } else {
                                    $.messager.show({
                                        title: 'Error',
                                        msg: data.message
                                    });
                                }
                            }
                        });
                    }
                });
            }
        }
    }
</script>
</body>
</html>